use dta\DataSet_v28.dta, clear

************************************************************************
************************* SAMPLE RESTRICTION ***************************
************************************************************************
keep if inlist(party, "sv", "dna", "sp", "v", "krf", "h", "frp", "h_fv")
keep if elected==1 & year>1944

************************************************************************
*****************A: Age in election year *******************************
************************************************************************
preserve
collapse age, by(year female)
tw (scatter age year  if female==0, msymbol(S) mcolor(gray) connect(l) lpattern(solid) lcolor(black)) ///
   (scatter age year  if female==1, msymbol(O) mcolor(black) connect(l) lpattern(solid) lcolor(black)), ///
title("") xtitle("Election year") ytitle("Average") title("Age in election year") xscale(range(1945 2021)) xlabel(1945(4)2021, angle(45) labsize(small)) plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s2mono) ylabel(40(5)60,angle(0)) legend(order(1 "Men" 2 "Women") col(2) region(lstyle(none))) yline(60, lstyle(foreground) lcolor(gs14))
graph save figures/gph/age.gph, replace
restore

************************************************************************
*****************B: High education *************************************
************************************************************************
preserve
merge m:1 year pid using "dta\MP_education"
keep if _merge==3

collapse high_education, by(year female)
tw (scatter high_education year if female==0, msymbol(S) mcolor(gray) connect(l) lpattern(solid) lcolor(black)) ///
   (scatter high_education year if female==1, msymbol(O) mcolor(black) connect(l) lpattern(solid) lcolor(black)), ///
title("") xtitle("Election year") ytitle("Fraction") title("High education") xscale(range(1945 2021)) xlabel(1945(4)2021, angle(45) labsize(small)) plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s2mono) ylabel(,angle(0)) legend(order(1 "Men" 2 "Women") pos(4) ring(0) col(1) region(lstyle(none)))
graph save figures/gph/education.gph, replace
restore

************************************************************************
*****************C: Experience from local council **********************
************************************************************************
gen council_first=0
replace council_first=1 if year>first_year_loc_council 
replace council_first=1 if year>first_year_loc_council_LCD

preserve
collapse council_first, by(year female)
tw (scatter council_first year  if female==0, msymbol(S) mcolor(gray) connect(l) lpattern(solid) lcolor(black)) ///
   (scatter council_first year  if female==1, msymbol(O) mcolor(black) connect(l) lpattern(solid) lcolor(black)), ///
title("") xtitle("Election year") ytitle("Fraction") title("Experience from local council") xscale(range(1945 2021)) xlabel(1945(4)2021, angle(45) labsize(small)) plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s2mono) ylabel(0(0.2)1.0,angle(0)) legend(order(1 "Men" 2 "Women") pos(4) ring(0) col(1) region(lstyle(none))) yline(1, lstyle(foreground) lcolor(gs14))
graph save figures/gph/council_first.gph, replace
restore

************************************************************************
*****************D: Experience as mayor ********************************
************************************************************************
gen mayor_first=0
replace mayor_first=1 if year>first_year_loc_mayor 
replace mayor_first=1 if year>first_year_loc_mayor_LCD

preserve
collapse mayor_first, by(year female)
tw (scatter mayor_first year  if female==0, msymbol(S) mcolor(gray) connect(l) lpattern(solid) lcolor(black)) ///
   (scatter mayor_first year  if female==1, msymbol(O) mcolor(black) connect(l) lpattern(solid) lcolor(black)), ///
title("") xtitle("Election year") ytitle("Fraction") title("Experience as local mayor") xscale(range(1945 2021)) xlabel(1945(4)2021, angle(45) labsize(small)) plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s2mono) ylabel(0(0.1)0.5,angle(0)) legend(order(1 "Men" 2 "Women") pos(1) ring(0) col(1) region(lstyle(none))) yline(0.5, lstyle(foreground) lcolor(gs14))
graph save figures/gph/mayor_first.gph, replace
restore

************************************************************************
************************* Combine **************************************
************************************************************************

cd figures/gph/
grc1leg age.gph education.gph council_first.gph mayor_first.gph, plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) 
graph export ../FigureA3.pdf, replace
cd ../../